package com.zr.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.zr.model.UserModel;
import com.zr.util.JdbcUtil;

/**
 * 匹配登录数据
 * @author Administrator
 *
 */
public class LoginDao {
	/**
	 * 查询是否匹配数据库的数据
	 * @param usermodel 
	 * @return 如果有则返回用户的权限，1为普通用户，2为管理员用户
	 */
	public int  validateUser(UserModel usermodel){
		int flag = 0;
		String sql = "select * from user where sid = ? and spwt = ?";
		Connection con = JdbcUtil.getDBConnection();
		try {
			PreparedStatement pst = con.prepareStatement(sql);
			pst.setInt(1, usermodel.getSid());
			pst.setString(2, usermodel.getSpwt());
			ResultSet rs = pst.executeQuery();
			while(rs.next()){
				usermodel.setSpower(rs.getInt("spower"));
			}
			flag =usermodel.getSpower();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			JdbcUtil.closedConnection(con);
		}
		return flag;
	}

	
}

